//
//  HMHomeTableViewCell.swift
//  WeiBoXR
//
//  Created by acer on 16/9/24.
//  Copyright © 2016年 acer. All rights reserved.
//

import UIKit
//  设置微博内容字体大小
let HMHomeTableViewCellFontSize: CGFloat = 14

class HMHomeTableViewCell: UITableViewCell {

    //  记录当前toolbar顶部约束
    var toolBarTopConstraint: Constraint?

    var statusViewModel: HMHomeCellViewModel? {
        didSet {
            originalView.statusViewModel = statusViewModel
            toolBarView.statusViewModel = statusViewModel
//            retweetView.statusViewModel = statusViewModel
            
            toolBarTopConstraint?.uninstall()

            //  判断其是否有转发微博
            if statusViewModel?.statusModel?.retweeted_status != nil {
                //  有转发微博
                //  更新约束,显示转发微博,绑定数据
                retweetView.isHidden = false
                toolBarView.snp_updateConstraints(closure: { (make) in
                    toolBarTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                
                retweetView.statusViewModel = statusViewModel
            } else {
                //  没有转发微博
                //  更新约束, 隐藏转发微博视图
                retweetView.isHidden = true
                toolBarView.snp_updateConstraints(closure: { (make) in
                    toolBarTopConstraint = make.top.equalTo(originalView.snp_bottom).constraint
                })
                
                
                
            }

        }
    }
    private var originalView: HMHomeOriginalView = { () -> HMHomeOriginalView in
        let view = HMHomeOriginalView()
        
        return view
    }()
    //  转发微博视图
    private lazy var retweetView: HMHomeRetWeetView = {
        let view = HMHomeRetWeetView()
        return view
    }()

    
    private lazy var toolBarView: HMHomeToolBarView = HMHomeToolBarView()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)

        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(toolBarView)
        
        originalView.snp_makeConstraints { (make) in
            make.top.leading.trailing.equalTo(contentView)
        }
        retweetView.snp_makeConstraints { (make) in
            make.top.equalTo(originalView.snp_bottom)
            make.leading.trailing.equalTo(originalView)
        }
        toolBarView.snp_makeConstraints { (make) in
            toolBarTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
            make.leading.trailing.equalTo(retweetView)
            make.height.equalTo(35)
            make.bottom.equalTo(contentView.snp_bottom)
        }

        
    }
    
    
    
    
    
    
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
